﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using PMSA.Framework.Database;

class CPromotionFacade
{
    private PromotionDAL db = new PromotionDAL();
    internal IList<Promotion> List(int pageIndex, int pageMax, int isActive)
    {
        IList<Promotion> list = null;
        DataSet ds = new DataSet();
        ds = db.List(pageIndex, pageMax, isActive);
        if (ds != null && ds.Tables.Count > 0)
        {
            list = CDb.MapList<Promotion>(ds.Tables[0]);
        }

        return list;
    }

    internal Promotion Detail(int Id)
    {
        DataSet ds = new DataSet();
        ds = db.Detail(Id);
        Promotion obj = CDb.Map<Promotion>(ds.Tables[0]);
        return obj;
    }

    internal Promotion Insert(string name, string title, string description, string content, string image, DateTime fromDate, DateTime toDate, int status, int isActive, string contentDetail)
    {
        DataSet ds = new DataSet();
        ds = db.Insert(name, title, description, content, image, fromDate, toDate, status, isActive, contentDetail);
        Promotion obj = CDb.Map<Promotion>(ds.Tables[0]);
        return obj;
    }

    internal Promotion Update(int id, string name, string title, string description, string content, string image, DateTime fromDate, DateTime toDate, int status, int isActive, string contentDetail)
    {
        DataSet ds = new DataSet();
        ds = db.Update(id, name, title, description, content, image, fromDate, toDate, status, isActive, contentDetail);
        Promotion obj = CDb.Map<Promotion>(ds.Tables[0]);
        return obj;
    }

    internal Promotion UpdateStatusActive(int id, int isActive)
    {
        DataSet ds = new DataSet();
        ds = db.UpdateStatusActive(id, isActive);
        Promotion obj = CDb.Map<Promotion>(ds.Tables[0]);
        return obj;
    }
}
